//
//Copyright GX. Yuan
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
 * @file net.go
 * @brief Leetcode 剑指Offer 第二版
 * @details 复杂链表的复制
 * @author GX. Yuan  any question please send mail to yuanguanxu@qq.com
 * @date 2021-6-28
 * @version V1.0
 * @attention 硬件平台: windows 10 家庭版
 * SDK版本：Go 1.16.5
 * IDE版本：GoLand 2020.2.3
 */
package main

//Definition for a Node.
type Node struct {
	Val    int
	Next   *Node
	Random *Node
}

func copyRandomList(head *Node) *Node {
	var mapval map[*Node]*Node
	mapval=make(map[*Node]*Node,10)
	cur:=head
	for cur!=nil {
		mapval[cur]=&Node{cur.Val,nil,nil}
		cur=cur.Next
	}
	cur=head
	for cur!=nil  {
		mapval[cur].Next=mapval[cur.Next]
		mapval[cur].Random=mapval[cur.Random]
		cur=cur.Next
	}
	return mapval[head]
}


func main() {

}

// 根据:k神 给出的思路
// 1. 利用映射的关系实现
// 2. 利用代码的拼接和拆分方式实现
// 关键的部分是：
// 在连接的随机中，我们判断节点之间的关系是根据节点地址；不能靠节点存储的值来实现；
